#include "tinyxml.h"
#include "stdafx.h"
#include "collada.h"

#ifdef _DEBUG
#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#define new DEBUG_NEW
#endif

using namespace Collada;

IMPLEMENT_RTTI( Collada::Library, Collada::Element )
IMPLEMENT_ELEMENT( Collada::Library )

Library::Library( const std::string& id, const std::string& name )
:	Element( id, name )
{
	CHILD_ELEMENT_BEGIN()
		CHILD_ELEMENT( "asset", Collada::Empty )
		CHILD_ELEMENT( "geometry", Collada::Geometry )
		CHILD_ELEMENT( "visual_scene", Collada::VisualScene )
		CHILD_ELEMENT( "extra", Collada::Empty )
	CHILD_ELEMENT_END()
}

Library::~Library()
{
}

bool Library::AddGeometry( Geometry* pGeometry )
{ 
	return _data->AddLibrary( _libraryId, pGeometry ); 
}

bool Library::AddVisualScene( VisualScene* pVisualScene )
{ 
	return _data->AddLibrary( _libraryId, pVisualScene );
}

void Library::AllChildElementsLoaded( Element* pParent )
{
	this->_isNotNeededAnymore = true;
}

void Library::Initialize( Element* pParent, const void* desc )
{
	TiXmlElement* pElem = ( TiXmlElement* )desc;
	_libraryId = Fundamental::JenkinsPHF( pElem->Value() );
	_data = ( Data* )pParent;
}

bool Library::IsValid( const void* desc )
{
	TiXmlElement* pElem = ( TiXmlElement* )desc;
	
	if( std::string( pElem->Value() ) == "library_geometries" )
	{
		if( pElem->FirstChildElement( "geometry" ) )
		{
			return true;
		}
	}

	if( std::string( pElem->Value() ) == "library_visual_scenes" )
	{
		if( pElem->FirstChildElement( "visual_scene" ) )
		{
			return true;
		}
	}

	return false;
}